$(function() {
    $.initPage(manpowerRequisitionDetail.load.start);
});

var manpowerRequisitionDetail = new BaseFrame();

manpowerRequisitionDetail.addBlock(
    'basicInformation',
    'erInformation',
    'businessInformation',
    'opsInformation',
    'taInformation',
    'operationInformation'
);

//load module
manpowerRequisitionDetail.load.addStart(function() {
    var params = {};
    params.taskList = [
        { keyName: 'businessNodeList', taskName: 'getBusinessNodeList' },
        { keyName: 'taGroupList', taskName: 'getTaGroupList' },
    ];
    $.getFormDetail(params)
        .then(function(data) {
            _data = $.extend({}, data);
            $('#form-detail').data('detail', $.extend({}, _data.formDetail ? _data.formDetail.formDetail : {}));
            return $.pageStart(_eLancoSettings);
        })
        .then(function() {
            if ($.isEmpty(_data.formDetail)) {
                $.alert(_enumMessage.noRecord, $.exitForm);
            } else {
                manpowerRequisitionDetail.event.runTask();
                manpowerRequisitionDetail.load.runTask();
                manpowerRequisitionDetail.verify.status();
                $('#btn-transfer').attr('disabled', 'disabled');
            };
        });
});

manpowerRequisitionDetail.load.addBind('createTitle', function() {
    var currentPage = $.getCurrentPage(_eLancoSettings.pageList);
    $('title').text(currentPage.title);
});

manpowerRequisitionDetail.load.addBind('createNav', function() {
    var navList = $.getUserAuthorityList(_user.roleList, _eLancoSettings.authorityList, _eLancoSettings.pageList);
    $('#logout').on('click', $.logoff);
    $('#block-nav').createNavList(navList).removeClass('dn');
});

manpowerRequisitionDetail.load.basicInformation.addBind('createBasicInformation', function() {
    var domStorage = $('#form-detail');
    var formDetail = domStorage.data('detail');
    var selectedEr = formDetail.approvalStep1Approver;
    if ($.isEmpty($.getParam('id'))) {
        formDetail.hiringManager = _user;
        $('#field-detail-hiringManager').createUser(domStorage, 'detail.hiringManager', { displayInTextBox: true });
        $('#field-detail-hiringManager').trigger('selectUserCallback', _user);
    } else {
        $('#field-detail-hiringManager').createUser(domStorage, 'detail.hiringManager', { displayInTextBox: true });
    }
    $('#field-detail-positionTitle').createString(domStorage, 'detail.positionTitle', {
        required: true,
    });
    $('#field-detail-businessNode1').createSelectOtherAndNo(domStorage, 'detail.businessNode1Code', 'detail.businessNode1', manpowerRequisitionDetail.load.businessNodeList(), {
        required: true,
    });
    $('#field-detail-businessNode2').createSelectOtherAndNo(domStorage, 'detail.businessNode2Code', 'detail.businessNode2', $('#field-detail-businessNode1').find('option:selected').data('data').childrenList, {
        required: true,
    });
    $('#field-detail-businessNode3').createSelectOtherAndNo(domStorage, 'detail.businessNode3Code', 'detail.businessNode3', $('#field-detail-businessNode2').find('option:selected').data('data').childrenList, {
        required: true,
    });
    $('#field-detail-businessNode4').createSelectOtherAndNo(domStorage, 'detail.businessNode4Code', 'detail.businessNode4', $('#field-detail-businessNode3').find('option:selected').data('data').childrenList, {
        required: true,
    });
    $('#field-detail-employeeType').createSelect(domStorage, 'detail.employeeType', 'detail.employeeTypeName', $.createDropdownList('employeeType'), {
        required: true,
    });
    $('#field-detail-costCenter').createInteger(domStorage, 'detail.costCenter', {
        required: true,
        attributes: { maxlength: 12 }
    });
    $('#field-detail-workingLocation').createLocation(domStorage, 'detail.workingLocationProvinceCode', 'detail.workingLocationProvince', 'detail.workingLocationCityCode', 'detail.workingLocationCity', {
        required: true,
    });
    $('#field-detail-er').createSelect(domStorage, 'detail.approvalStep1Approver', $.createApprovalList(1), {
        required: true,
    });
    if (!$.isEmpty(selectedEr)) {
        setTimeout(function() {
            $('#field-detail-er').reloadSelectedOption(selectedEr);
        }, 0);
    }
    $('#block-basic-information').removeClass('dn');
});

manpowerRequisitionDetail.load.erInformation.addBind('createErInformation', function() {
    var domStorage = $('#form-detail');
    domStorage.data('detail').forwardToOtherEr = '';
    $('#field-detail-forwardToOtherEr').createSelect(domStorage, 'detail.forwardToOtherEr', $.createApprovalList(1));
    $('#field-detail-jobNumber').createString(domStorage, 'detail.jobNumber', {
        required: true,
    });
    $('#field-detail-erComment').createTextarea(domStorage, 'detail.erComment');
    $('#field-detail-business').createUser(domStorage, 'detail.business', { displayInTextBox: true });
    $('#block-er-information').removeClass('dn');
});

manpowerRequisitionDetail.load.businessInformation.addBind('createBusinessInformation', function() {
    var domStorage = $('#form-detail');
    $('#field-detail-businessComment').createTextarea(domStorage, 'detail.businessComment', {
        required: true,
    });
    $('#block-bussiness-information').removeClass('dn');
});

manpowerRequisitionDetail.load.opsInformation.addBind('createOpsInformation', function() {
    var domStorage = $('#form-detail');
    $('#field-detail-ta').createSelect(domStorage, 'detail.approvalStep4Role', _data.taGroupList, {
        required: true,
    });
    $('#field-detail-positionId').createString(domStorage, 'detail.positionId', {
        required: true,
    });
    $('#field-detail-opsComment').createTextarea(domStorage, 'detail.opsComment', {
        required: true,
    });
    $('#block-ops-information').removeClass('dn');
});

manpowerRequisitionDetail.load.taInformation.addBind('createTaInformation', function() {
    var domStorage = $('#form-detail');
    $('#field-detail-taComment').createTextarea(domStorage, 'detail.taComment', {
        required: true,
    });
    $('#field-detail-cancel-taComment').createTextarea(domStorage, 'detail.taCancelComment', {
        required: true,
    });
    $('#block-ta-information').removeClass('dn');
});

manpowerRequisitionDetail.load.operationInformation.addBind('createOperationInformation', function() {
    $('#block-operation-information').removeClass('dn');    
});

manpowerRequisitionDetail.load.addEvent('businessNodeList', function() {
    var getChildrenList = function(childrenList) {
        var _childrenList = [];
        if ($.isEmpty(childrenList)) return _childrenList;
        for (var i = 0; i < childrenList.length; i++) {
            var childrenItem = childrenList[i];
            _childrenList.push({
                key: childrenItem.value,
                value: childrenItem.value,
                childrenList: getChildrenList(childrenItem.childrenList),
                defaultErEmployeeId: childrenItem.defaultErEmployeeId,
            });
        }
        return _childrenList;
    }
    var businessNodeList = [];
    for (var i = 0; i < _data.businessNodeList.length; i++) {
        var businessNodeItem = _data.businessNodeList[i];
        businessNodeList.push({
            key: businessNodeItem.value,
            value: businessNodeItem.value,
            childrenList: getChildrenList(businessNodeItem.childrenList),
            defaultErEmployeeId: businessNodeItem.defaultErEmployeeId,
        });
    }
    return businessNodeList;
});

//event module
manpowerRequisitionDetail.event.basicInformation.addBind('hiringManagerChange', function() {
    $('#field-detail-hiringManager').on('selectUserCallback', function(event, user) {
        var params = {
            customMethodName: 'manpowerRequisitionGetHiringManager',
            customMethodParams: {
                hiringManager: user
            }
        };
        $.post(_apiPath + '/eLancos/customMethod', params)
            .then(function(data) {
                var businessNode1Dom = $('#field-detail-businessNode1');
                var businessNode2Dom = $('#field-detail-businessNode2');
                var businessNode3Dom = $('#field-detail-businessNode3');
                var businessNode4Dom = $('#field-detail-businessNode4');
                var userData = $('#field-detail-hiringManager tr[data]').data('data');
                $('#field-detail-hiringManager tr[data]').data('data', $.extend({}, userData, data));
                businessNode1Dom.reloadSelectedOption(data.businessNode1);
                var node1Value = businessNode1Dom.findFormUnit().find('option:selected').data('data');
                if ($.isEmpty(node1Value.key)) businessNode1Dom.reloadBusinessSelected(data.businessNode1, businessNode1Dom);
                var businessNode2OptionList = node1Value.childrenList;
                businessNode2OptionList = businessNode2OptionList.concat([_otherSelect, _noSelect]);
                businessNode2Dom.reloadOptionList(businessNode2OptionList).reloadSelectedOption(data.businessNode2);
                var node2Value = businessNode2Dom.findFormUnit().find('option:selected').data('data');
                if ($.isEmpty(node2Value.key)) businessNode2Dom.reloadBusinessSelected(data.businessNode2, businessNode2Dom);
                var businessNode3OptionList = node2Value.childrenList;
                businessNode3OptionList = businessNode3OptionList.concat([_otherSelect, _noSelect]);
                businessNode3Dom.reloadOptionList(businessNode3OptionList).reloadSelectedOption(data.businessNode3);
                var node3Value = businessNode3Dom.findFormUnit().find('option:selected').data('data');
                if ($.isEmpty(node3Value.key)) businessNode3Dom.reloadBusinessSelected(data.businessNode3, businessNode3Dom);
                var businessNode4OptionList = node3Value.childrenList;
                businessNode4OptionList = businessNode4OptionList.concat([_otherSelect, _noSelect]);
                businessNode4Dom.reloadOptionList(businessNode4OptionList).reloadSelectedOption(data.businessNode4);
                var node4Value = businessNode4Dom.findFormUnit().find('option:selected').data('data');
                if ($.isEmpty(node4Value.key)) businessNode4Dom.reloadBusinessSelected(data.businessNode4, businessNode4Dom);
            });
    });
});

manpowerRequisitionDetail.event.basicInformation.addBind('businessNodeChange', function() {
    var domStorage = $('#form-detail');
    var approvalStep = _data.formDetail.approvalStep;
    $('#field-detail-businessNode1').on('changeCallback', function(event, value) {
        var thisDom = $(this);
        var businessNode2Dom = $('#field-detail-businessNode2');
        var data = thisDom.findFormUnit().find('option:selected').data('data');
        var optionList = data.childrenList;
        if (!$.isEmpty(value)) optionList = optionList.concat([_otherSelect, _noSelect]);
        if (businessNode2Dom.findFormUnit().length == 0) {
            businessNode2Dom.on('createCallback', function() {
                $.isEmpty(approvalStep) ? businessNode2Dom.findFormUnit().val(null).trigger('change') : '';
                businessNode2Dom.reloadOptionList(optionList).reloadSelectedOption();
            });
        } else {
            $.isEmpty(approvalStep) ? businessNode2Dom.findFormUnit().val(null).trigger('change') : '';
            businessNode2Dom.reloadOptionList(optionList).reloadSelectedOption();
        }
        if (!$.isEmpty(value)) {
            manpowerRequisitionDetail.event.basicInformation.defaultErSelected(data.defaultErEmployeeId);
        }
    });
    $('#field-detail-businessNode2').on('changeCallback', function(event, value) {
        var thisDom = $(this);
        var businessNode3Dom = $('#field-detail-businessNode3');
        var data = thisDom.findFormUnit().find('option:selected').data('data');
        var optionList = data.childrenList;
        if (!$.isEmpty(value)) optionList = optionList.concat([_otherSelect, _noSelect]);
        if (businessNode3Dom.findFormUnit().length == 0) {
            businessNode3Dom.on('createCallback', function() {
                $.isEmpty(approvalStep) ? businessNode3Dom.findFormUnit().val(null).trigger('change') : '';
                businessNode3Dom.reloadOptionList(optionList).reloadSelectedOption();
            });
        } else {
            $.isEmpty(approvalStep) ? businessNode3Dom.findFormUnit().val(null).trigger('change') : '';
            businessNode3Dom.reloadOptionList(optionList).reloadSelectedOption();
        }
        if (!$.isEmpty(value)) {
            manpowerRequisitionDetail.event.basicInformation.defaultErSelected(data.defaultErEmployeeId);
        }
    });
    $('#field-detail-businessNode3').on('changeCallback', function(event, value) {
        var thisDom = $(this);
        var businessNode4Dom = $('#field-detail-businessNode4');
        var data = thisDom.findFormUnit().find('option:selected').data('data');
        var optionList = data.childrenList;
        if (!$.isEmpty(value)) optionList = optionList.concat([_otherSelect, _noSelect]);
        if (businessNode4Dom.findFormUnit().length == 0) {
            businessNode4Dom.on('createCallback', function() {
                $.isEmpty(approvalStep) ? businessNode4Dom.findFormUnit().val(null).trigger('change') : '';
                businessNode4Dom.reloadOptionList(optionList).reloadSelectedOption();
            });
        } else {
            $.isEmpty(approvalStep) ? businessNode4Dom.findFormUnit().val(null).trigger('change') : '';
            businessNode4Dom.reloadOptionList(optionList).reloadSelectedOption();
        }
        if (!$.isEmpty(value)) {
            manpowerRequisitionDetail.event.basicInformation.defaultErSelected(data.defaultErEmployeeId);
        }
    });
    $('#field-detail-businessNode4').on('changeCallback', function(event, value) {
        var thisDom = $(this);
        var data = thisDom.findFormUnit().find('option:selected').data('data');
        if (!$.isEmpty(value)) {
            manpowerRequisitionDetail.event.basicInformation.defaultErSelected(data.defaultErEmployeeId);
        }
    });
});

manpowerRequisitionDetail.event.basicInformation.addEvent('defaultErSelected', function(defaultErEmployeeId) {
    var erDom = $('#field-detail-er');
    var userData = $('#field-detail-hiringManager tr[data]').data('data');
    if (!$.isEmpty(userData) && !userData.isSales) defaultErEmployeeId = 'C251507';
    if (erDom.findFormUnit().length == 0) {
        erDom.on('createCallback', function() {
            erDom.reloadSelectedOption(defaultErEmployeeId);
        })
    } else {
        erDom.reloadSelectedOption(defaultErEmployeeId);
    }
});

manpowerRequisitionDetail.event.erInformation.addBind('forwardToOtherErChange', function() {
    $('#field-detail-forwardToOtherEr').on('changeCallback', function(event, value) {
        var domStorage = $('#form-detail');
        if ($.isEmpty(value)) {
            $('#field-detail-jobNumber').enabledForm();
            $('#field-detail-erComment').enabledForm();
            $('#field-detail-business').enabledForm();
            $('#btn-approve').removeAttr('disabled');
            $('#btn-reject').removeAttr('disabled');
            $('#btn-return').removeAttr('disabled');
            $('#btn-transfer').attr('disabled', 'disabled');
        } else {
            $('#field-detail-jobNumber').findFormUnit().val(null).trigger('change').verifyClean();
            $('#field-detail-erComment').findFormUnit().val(null).trigger('change').verifyClean();
            domStorage.data('detail').business = {};
            $('#field-detail-business .component-table-user tr[data]').remove();
            $('#field-detail-jobNumber').disabledForm();
            $('#field-detail-erComment').disabledForm();
            $('#field-detail-business').disabledForm();
            $('#btn-approve').attr('disabled', 'disabled');
            $('#btn-reject').attr('disabled', 'disabled');
            $('#btn-return').attr('disabled', 'disabled');
            $('#btn-transfer').removeAttr('disabled');
        }
    });
});

manpowerRequisitionDetail.event.operationInformation.addBind('operation', function() {
    $('#block-operation-information').on('click', '.btn[save]', manpowerRequisitionDetail.form.saveForm);

    $('#block-operation-information').on('click', '.btn[submit]', function() {
        if (!manpowerRequisitionDetail.verify.submitForm()) return false;
        manpowerRequisitionDetail.form.submitForm();
    });

    $('#block-operation-information').on('click', '.btn[approve], .btn[kickoff]', function() {
        if (!manpowerRequisitionDetail.verify.approveForm()) return false;
        manpowerRequisitionDetail.form.approveForm();
    });

    $('#block-operation-information').on('click', '.btn[reject]', manpowerRequisitionDetail.form.rejectForm);

    $('#block-operation-information').on('click', '.btn[cancel]', manpowerRequisitionDetail.form.cancelForm);

    $('#block-operation-information').on('click', '.btn[handover]', function() {
        if (!manpowerRequisitionDetail.verify.handoverForm()) return false;
        manpowerRequisitionDetail.form.handoverForm();
    });

    $('#block-operation-information').on('click', '.btn[revocation]', function() {
        if (!manpowerRequisitionDetail.verify.revocationForm()) return false;
        manpowerRequisitionDetail.form.revocationForm();
    });

    $('#block-operation-information').on('click', '.btn[exit]', manpowerRequisitionDetail.form.exitForm);
});

//form module
manpowerRequisitionDetail.form.addEvent('saveForm', function() {
    var id = $.isEmpty($.getParam('id')) ? 0 : $.getParam('id');
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = manpowerRequisitionDetail.save.formDetail();
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail
    });
    $.post(_apiPath + '/eLancos/FormDetails/' + id + '/Save', params)
        .then(function(data) {
            $.alert(_enumMessage.saveSuccess, manpowerRequisitionDetail.form.exitForm);
        });
});

manpowerRequisitionDetail.form.addEvent('submitForm', function() {
    var id = $.isEmpty($.getParam('id')) ? 0 : $.getParam('id');
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = manpowerRequisitionDetail.save.formDetail();
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail
    });
    if($.isEmpty(_data.formDetail.historyId) && formId == 2) {
        params.reSubmit = false;
    }else {
        params.reSubmit = true;
        params.formDetail.taComment = '';
        params.formDetail.opsComment = '';
        params.formDetail.erComment = '';
    }
    $.post(_apiPath + '/eLancos/FormDetails/' + id + '/Submit', params)
        .then(function(data) {
            $.alert(_enumMessage.submitSuccess, manpowerRequisitionDetail.form.exitForm);
        });
});

manpowerRequisitionDetail.form.addEvent('approveForm', function() {
    var id = $.isEmpty($.getParam('id')) ? 0 : $.getParam('id');
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = manpowerRequisitionDetail.save.formDetail();
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail
    });
    $.post(_apiPath + '/eLancos/FormDetails/' + id + '/Approval', params)
        .then(function(data) {
            $.alert(_enumMessage.approveSuccess, manpowerRequisitionDetail.form.exitForm);
        });
});

manpowerRequisitionDetail.form.addEvent('rejectForm', function() {
    var formDetail = manpowerRequisitionDetail.save.formDetail();
    var id = $.isEmpty($.getParam('id')) ? 0 : $.getParam('id');
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = manpowerRequisitionDetail.save.formDetail();
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail
    });
    $.post(_apiPath + '/eLancos/FormDetails/' + id + '/Reject', params)
        .then(function(data) {
            $.alert(_enumMessage.rejectSuccess, manpowerRequisitionDetail.form.exitForm);
        });
});

manpowerRequisitionDetail.form.addEvent('cancelForm', function() {
    var id = $.isEmpty($.getParam('id')) ? 0 : $.getParam('id');
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = manpowerRequisitionDetail.save.formDetail();
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail,
        returnform: 'return',
    });
    $.post(_apiPath + '/eLancos/FormDetails/' + id + '/Save', params)
        .then(function(data) {
            return $.post(_apiPath + '/ELancos/FormDetails/' + id + '/Cancel', params);
        }).then(function(data) {
            $.alert(_enumMessage.rejectSaveSuccess, manpowerRequisitionDetail.form.exitForm);
        });
});

manpowerRequisitionDetail.form.addEvent('handoverForm', function() {
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = manpowerRequisitionDetail.save.formDetail();
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail,
        customMethodName: 'forwardToApprover',
        customMethodParams: {
            targetApprovalStep: _data.formDetail.approvalStep,
            forwardToOtherApprover: formDetail.forwardToOtherEr
        },
        forwordBeforeApprover: _data.formDetail.approvalList[0].approver
    });
    $.post(_apiPath + '/eLancos/customMethod', params)
        .then(function(data) {
            $.alert(manpowerRequisitionDetail.message.erInformation.handoverSuccess, manpowerRequisitionDetail.form.exitForm);
        });
});

manpowerRequisitionDetail.form.addEvent('revocationForm', function() {
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = manpowerRequisitionDetail.save.formDetail();
    var approvalListEmailNeed = [];
    _data.formDetail.approvalList.forEach(function(approvalItem) {
        approvalListEmailNeed.push({
            approvalStatus: approvalItem.approvalStatus,
            approver: {
                email: approvalItem.approver.email
            },
        })
    });
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail,
        approvalListEmailNeed: approvalListEmailNeed,
        customMethodName: 'manpowerRequisitionRevocationForm',
        customMethodParams: {}
    });
    $.post(_apiPath + '/eLancos/customMethod', params)
        .then(function(data) {
            $.alert(manpowerRequisitionDetail.message.taInformation.revocationSuccess, manpowerRequisitionDetail.form.exitForm);
        });
});

manpowerRequisitionDetail.form.addEvent('exitForm', $.exitForm);

//save module
manpowerRequisitionDetail.save.addEvent('formDetail', function() {
    var formStatus = _data.formDetail.formStatus;
    var formDetail = $.extend({}, $('#form-detail').data('detail'));
    if (!$.isEmpty(formDetail.hiringManager)) {
        formDetail.hiringManagerEmployeeId = formDetail.hiringManager.employeeId;
    } else {
        formDetail.hiringManagerEmployeeId = '';
    }
    if (!$.isEmpty(formDetail.business)) {
        formDetail.approvalStep2Approver = formDetail.hiringManager.employeeId;
    } else {
        formDetail.approvalStep2Approver = '';
    }
    if (formStatus == _enumFormStatus.submitted) {
        formDetail.comment = formDetail.erComment;
    } else if (formStatus == _enumFormStatus.approved1) {
        formDetail.comment = formDetail.businessComment;
    } else if (formStatus == _enumFormStatus.approved2) {
        formDetail.comment = formDetail.opsComment;
    } else if (formStatus == _enumFormStatus.approved3) {
        formDetail.comment = formDetail.taComment;
    }
    return formDetail;
});

//verify module
manpowerRequisitionDetail.verify.addEvent('submitForm', function() {
    var judge = true;
    var data = $('#form-detail').data('detail');
    $('#form-detail *[form]').findFormUnit().verifyClean();
    _message = '\n' + _enumMessage.operationError;
    if ($.isEmpty(data.hiringManager) || $('#field-detail-hiringManager').findFormUnit().val() != (data.hiringManager.employeeId + ' / ' + data.hiringManager.chineseName) ) {
        judge = false;
        $('#field-detail-hiringManager').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.hiringManagerRequired);
    }
    if ($.isEmpty(data.positionTitle)) {
        judge = false;
        $('#field-detail-positionTitle').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.positionTitleRequired);
    }
    if ($.isEmpty(data.businessNode1Code)) {
        judge = false;
        $('#field-detail-businessNode1').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.businessNode1Required);
    } else {
        if (data.businessNode1Code == _otherSelect.key && $.isEmpty(data.businessNode1)) {
            judge = false;
            $('#field-detail-businessNode1 .component-select-other-other').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.businessNode1Required);
        }
    }
    if ($.isEmpty(data.businessNode2Code)) {
        judge = false;
        $('#field-detail-businessNode2').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.businessNode2Required);
    } else {
        if (data.businessNode2Code == _otherSelect.key && $.isEmpty(data.businessNode2)) {
            judge = false;
            $('#field-detail-businessNode2 .component-select-other-other').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.businessNode2Required);
        }
    }
    if ($.isEmpty(data.businessNode3Code)) {
        judge = false;
        $('#field-detail-businessNode3').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.businessNode3Required);
    } else {
        if (data.businessNode3Code == _otherSelect.key && $.isEmpty(data.businessNode3)) {
            judge = false;
            $('#field-detail-businessNode3 .component-select-other-other').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.businessNode3Required);
        }
    }
    if ($.isEmpty(data.businessNode4Code)) {
        judge = false;
        $('#field-detail-businessNode4').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.businessNode4Required);
    } else {
        if (data.businessNode4Code == _otherSelect.key && $.isEmpty(data.businessNode4)) {
            judge = false;
            $('#field-detail-businessNode4 .component-select-other-other').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.businessNode4Required);
        }
    }
    if ($.isEmpty(data.employeeType)) {
        judge = false;
        $('#field-detail-employeeType').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.employeeTypeRequired);
    }
    if (Number(data.costCenter) == null || Number(data.costCenter) == undefined || isNaN(Number(data.costCenter)) || Number(data.costCenter) == 0) {
        judge = false;
        $('#field-detail-costCenter').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.costCenterRequired);
    }
    if ($.isEmpty(data.workingLocationProvinceCode)) {
        judge = false;
        $('#field-detail-workingLocation .province').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.workingLocationRequired);
    }
    if ($.isEmpty(data.workingLocationCityCode)) {
        judge = false;
        $('#field-detail-workingLocation .city').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.workingLocationRequired);
    } else {
        if (data.workingLocationCityCode == _otherSelect.key && $.isEmpty(data.workingLocationCity)) {
            judge = false;
            $('#field-detail-workingLocation .city .component-select-other-other').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.workingLocationRequired);
        }
    }
    if ($.isEmpty(data.approvalStep1Approver)) {
        judge = false;
        $('#field-detail-er').verifyErrorAndHelp(manpowerRequisitionDetail.message.basicInformation.erRequired);
    }
    if (!judge) $.alert(_message);
    return judge;
});

manpowerRequisitionDetail.verify.addEvent('approveForm', function() {
    var judge = true;
    var data = $('#form-detail').data('detail');
    var formStatus = _data.formDetail.formStatus
    $('#form-detail *[form]').findFormUnit().verifyClean();
    _message = '\n' + _enumMessage.operationError;
    if (formStatus == _enumFormStatus.submitted) {
        if ($.isEmpty(data.jobNumber)) {
            judge = false;
            $('#field-detail-jobNumber').verifyErrorAndHelp(manpowerRequisitionDetail.message.erInformation.jobNumberRequired);
        }
        if ($.isEmpty(data.business)){
            judge = false;
            $('#field-detail-business').verifyErrorAndHelp(manpowerRequisitionDetail.message.erInformation.businessRequired);
        } else {
            if(!!$('#field-detail-business').findFormUnit().val() && $('#field-detail-business').findFormUnit().val() != (data.business.employeeId + ' / ' + data.business.chineseName)) {
                judge = false;
                $('#field-detail-business').verifyErrorAndHelp(manpowerRequisitionDetail.message.erInformation.businessFormat);
            }
            var bizValue = $('#field-detail-business').findFormUnit().val();
            if ($.isEmpty(bizValue)){
                judge = false;
                $('#field-detail-business').verifyErrorAndHelp(manpowerRequisitionDetail.message.erInformation.businessRequired);
            }
        }
    } else if (formStatus == _enumFormStatus.approved2) {
        if ($.isEmpty(data.approvalStep4Role)) {
            judge = false;
            $('#field-detail-ta').verifyErrorAndHelp(manpowerRequisitionDetail.message.taInformation.taRequired);
        }
        if ($.isEmpty(data.positionId)) {
            judge = false;
            $('#field-detail-positionId').verifyErrorAndHelp(manpowerRequisitionDetail.message.taInformation.positionIdRequired);
        }
    }
    if (!judge) $.alert(_message);
    return judge;
});

manpowerRequisitionDetail.verify.addEvent('handoverForm', function() {
    var judge = true;
    var data = $('#form-detail').data('detail');
    $('#form-detail *[form]').findFormUnit().verifyClean();
    _message = '\n' + _enumMessage.operationError;
    if (_data.formDetail.formStatus == _enumFormStatus.submitted) {
        if ($.isEmpty(data.forwardToOtherEr)) {
            judge = false;
            $('#field-detail-forwardToOtherEr').verifyErrorAndHelp(manpowerRequisitionDetail.message.erInformation.forwardToOtherErRequired);
        }
    }
    if (!judge) $.alert(_message);
    return judge;
});

manpowerRequisitionDetail.verify.addEvent('status', function() {
    var data = _data.formDetail;
    var formDetail = data.formDetail;
    var formStatus = $.toNumber(data.formStatus);
    if (!manpowerRequisitionDetail.verify.isRequester() &&
        !manpowerRequisitionDetail.verify.isApprover() &&
        !manpowerRequisitionDetail.verify.isViewer()) {
        return $.alert(_enumMessage.forbidden, manpowerRequisitionDetail.form.exitForm);
    }
    $('#block-er-information').addClass('dn');
    $('#block-bussiness-information').addClass('dn');
    $('#block-ops-information').addClass('dn');
    $('#block-ta-information').addClass('dn');
    $('#block-ta-cancel-information').addClass('dn');
    $('#form-detail').disabledForm();
    $('#block-operation-information').enabledForm();
    $('#block-operation-information .btn[exit]').removeClass('dn');
    if ($.isEmpty(data.id)) {
        $('#form-detail').enabledForm();
        $('#block-operation-information').find('.btn[save], .btn[submit]').removeClass('dn');
        return false;
    }
    switch (formStatus) {
        case _enumFormStatus.saved:
            if (manpowerRequisitionDetail.verify.isRequester()) {
                $('#form-detail').enabledForm();
                $('#block-operation-information').find('.btn[save], .btn[submit]').removeClass('dn');
            } else {
                return $.alert(_enumMessage.forbidden, manpowerRequisitionDetail.form.exitForm);
            }
            break;
        case _enumFormStatus.submitted:
            if (manpowerRequisitionDetail.verify.isApprover()) {
                $('#block-er-information').removeClass('dn');
                $('#block-er-information').enabledForm();
                $('#block-operation-information').find('.btn[approve], .btn[reject], .btn[handover], .btn[cancel]').removeClass('dn');
            }
            break;
        case _enumFormStatus.approved1:
            $('#block-er-information').removeClass('dn');
            if (manpowerRequisitionDetail.verify.isApprover()) {
                $('#block-bussiness-information').removeClass('dn');
                $('#block-bussiness-information').enabledForm();
                $('#block-operation-information').find('.btn[approve], .btn[reject]').removeClass('dn');
            }
            break;
        case _enumFormStatus.rejected1:
            $('#block-er-information').removeClass('dn');
            break;
        case _enumFormStatus.approved2:
            $('#block-er-information').removeClass('dn');
            if (!$.isEmpty(formDetail.business)) {
                $('#block-bussiness-information').removeClass('dn');
            }
            if (manpowerRequisitionDetail.verify.isApprover()) {
                $('#block-ops-information').removeClass('dn');
                $('#block-ops-information').enabledForm();
                $('#block-operation-information').find('.btn[approve]').removeClass('dn');
            }
            break;
        case _enumFormStatus.rejected2:
            $('#block-er-information').removeClass('dn');
            if (!$.isEmpty(formDetail.business)) {
                $('#block-bussiness-information').removeClass('dn');
            }
            break;
        case _enumFormStatus.approved3:
            $('#block-er-information').removeClass('dn');
            if (!$.isEmpty(formDetail.business)) {
                $('#block-bussiness-information').removeClass('dn');
            }
            $('#block-ops-information').removeClass('dn');
            if (manpowerRequisitionDetail.verify.isApprover()) {
                $('#block-ta-information').removeClass('dn');
                $('#field-detail-taComment').enabledForm();
                $('#block-operation-information').find('.btn[kickoff]').removeClass('dn');
            }
            break;
        case _enumFormStatus.rejected3:
            $('#block-er-information').removeClass('dn');
            if (!$.isEmpty(formDetail.business)) {
                $('#block-bussiness-information').removeClass('dn');
            }
            $('#block-ops-information').removeClass('dn');
            break;
        case _enumFormStatus.completed:
            $('#block-er-information').removeClass('dn');
            if (!$.isEmpty(formDetail.business)) {
                $('#block-bussiness-information').removeClass('dn');
            }
            $('#block-ops-information').removeClass('dn');
            $('#block-ta-information').removeClass('dn');
            if (manpowerRequisitionDetail.verify.isTaApprover()) {
                $('#field-detail-cancel-taComment').enabledForm();
                $('#block-operation-information').find('.btn[revocation]').removeClass('dn');
            }
            break;
        case _enumFormStatus.rejected4:
            $('#block-er-information').removeClass('dn');
            if (!$.isEmpty(formDetail.business)) {
                $('#block-bussiness-information').removeClass('dn');
            }
            $('#block-ops-information').removeClass('dn');
            $('#block-ta-information').removeClass('dn');
            $('#block-ta-cancel-information').removeClass('dn');
            break;
        default:
            break;
    }
});

manpowerRequisitionDetail.verify.addEvent('isRequester', function() {
    var judge = false
    var data = _data.formDetail;
    var formDetail = data.formDetail;
    if ($.isEmpty(data.id)) judge = true;
    if (_user.employeeId == data.sys_owner) judge = true;
    return judge;
});

manpowerRequisitionDetail.verify.addEvent('isApprover', function() {
    var judge = false;
    var data = _data.formDetail;
    var formDetail = data.formDetail;
    var approvalList = data.approvalList;
    if ($.isEmpty(data.id)) return judge;
    if ($.isEmpty(approvalList)) return judge;
    for (var i = 0; i < approvalList.length; i++) {
        var approvalItem = approvalList[i];
        if (approvalItem.approverEmployeeId == _user.employeeId &&
            approvalItem.approvalStep == data.approvalStep) {
            judge = true;
        }
    }
    return judge;
});

manpowerRequisitionDetail.verify.addEvent('isViewer', function() {
    var judge = false;
    var data = _data.formDetail;
    var approvalList = data.approvalList;
    for (var i = 0; i < approvalList.length; i++) {
        var approvalItem = approvalList[i];
        if (approvalItem.approvalStatus != _enumApprovalStatus.待审批 &&
            approvalItem.approvalStep != data.approvalStep) {
            judge = true;
        }
    }
    return judge;
});

manpowerRequisitionDetail.verify.addEvent('isTaApprover', function() {
    var judge = false;
    var data = _data.formDetail;
    if (data.formStatus == _enumFormStatus.completed) {
        var approvalList = data.approvalList;
        for (var i = 0; i < approvalList.length; i++) {
            var approvalItem = approvalList[i];
            if (approvalItem.approvalStatus != _enumApprovalStatus.待审批 &&
                approvalItem.approvalStep == data.approvalStep &&
                 _user.employeeId == approvalItem.approver.employeeId ) {
                judge = true;
            }
        }
    }
    return judge;
});

manpowerRequisitionDetail.verify.addEvent('revocationForm', function() {
    var judge = true;
    var data = $('#form-detail').data('detail');
    if ($.isEmpty(data.taCancelComment)) {
        judge = false;
        $('#field-detail-cancel-taComment').verifyErrorAndHelp(manpowerRequisitionDetail.message.taInformation.taCommentRequired);
    }
    return judge;
});

//message module
manpowerRequisitionDetail.message.basicInformation.addConfig('hiringManagerRequired', '用人经理必填');
manpowerRequisitionDetail.message.basicInformation.addConfig('positionTitleRequired', '职位名称必填');
manpowerRequisitionDetail.message.basicInformation.addConfig('businessNode1Required', '业务部门1必填');
manpowerRequisitionDetail.message.basicInformation.addConfig('businessNode2Required', '业务部门2必填');
manpowerRequisitionDetail.message.basicInformation.addConfig('businessNode3Required', '业务部门3必填');
manpowerRequisitionDetail.message.basicInformation.addConfig('businessNode4Required', '业务部门4必填');
manpowerRequisitionDetail.message.basicInformation.addConfig('employeeTypeRequired', '员工类型必填');
manpowerRequisitionDetail.message.basicInformation.addConfig('costCenterRequired', '成本中心必填,请输入数字');
manpowerRequisitionDetail.message.basicInformation.addConfig('workingLocationRequired', '工作地点必填');
manpowerRequisitionDetail.message.basicInformation.addConfig('erRequired', '员工关系经理必填');

manpowerRequisitionDetail.message.erInformation.addConfig('jobNumberRequired', '薪资级别必填');
manpowerRequisitionDetail.message.erInformation.addConfig('forwardToOtherErRequired', '转给其他ER必填');
manpowerRequisitionDetail.message.erInformation.addConfig('handoverSuccess', '转给其他ER成功');

manpowerRequisitionDetail.message.taInformation.addConfig('taRequired', 'TA必填');
manpowerRequisitionDetail.message.taInformation.addConfig('taRequired', 'TA必填');
manpowerRequisitionDetail.message.taInformation.addConfig('revocationSuccess', '取消招聘成功');

manpowerRequisitionDetail.message.erInformation.addConfig('businessFormat', '你的business值格式不正确');
manpowerRequisitionDetail.message.erInformation.addConfig('businessRequired', '业务审批人必填');

manpowerRequisitionDetail.message.taInformation.addConfig('taCommentRequired', '取消招聘原因必填');
//data module